var solrmgr;
var Manager;

dojo.declare("Main", wm.Page, {
    "preferredDevice": "desktop",
    start: function() {
        this.initializeAjaxSolrManager();
    },

    initializeAjaxSolrManager: function() {
        console.log("Starting the start function", this);
        Manager = new AjaxSolr.Manager({
            //proxyUrl: 'solr/'
            solrUrl: '/solr/'
        });
        solrmgr = Manager;
        console.log("calling Manager.init");
        Manager.init();

        Manager.addWidget(new AjaxSolr.ResultWidget({
            id: 'result',
            target: 'solr-results'
        }));
        
        Manager.addWidget(new AjaxSolr.PagerWidget({
            id: 'pager',
            target: 'solr-pager',
//            prevLabel: '&lt;',
//            nextLabel: '&gt;',
            innerWindow: 1,
            renderHeader: function (perPage, offset, total) {
                //Remove Jquery Dependency
                //$('#pager-header').html($('<span/>').text('displaying ' + Math.min(total, offset + 1) + ' to ' + Math.min(total, offset + perPage) + ' of ' + total));
//                var text = 'displaying ' + Math.min(total, offset + 1) + ' to ' + Math.min(total, offset + perPage) + ' of ' + total;
//                dojo.html.set(dojo.byId('pager-header'),'<span>'+text+'</span>',{parseContent : true});
                dojo.html.set(dojo.byId('pager-header').innerHTML = '<span> | Displaying ' + Math.min(total, offset + 1) + ' to ' + Math.min(total, offset + perPage) + ' of ' + total+'</span>');
            }
        }));
    },

    buttonSolrSearchClick: function(inSender) {
        
        console.log("Building basic solr query");
/*        
These things are now unnecessary as these parameters are set as part of the $.ajax call in the app script        
        Manager.store.remove('fq'); // Remove any previous filters and clear filter cache so that the entire data set is being searched
        Manager.store.addByValue('q', '*:*'); // Set the query to all
        Manager.store.addByValue('fq', this.textSearchBox.getValue("dataValue")); // set the query filter based on the text input from the user
        Manager.store.addByValue('rows', this.textMaxSearchResults.getValue("dataValue")); // set the maximum number of results to return based on the input from the user
*/
        console.log("Attempting to talk to solr");
        Manager.doRequest();

        console.log("Response", Manager.response);
        console.log("Completed the start function");
	},

    _end: 0
});